#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int y11[2076] = {0};
int month[]={31,29,31,30,31,30,31,31,30,31,30,31};

bool isrun(int year){
    if(year%400==0||(year%4==0&&year%100!=0))return true;
    return false;
}

void solve(){
    int k,l,r;
    cin>>k>>l>>r;
    vector<int> add(366,0);
    
    for (int y = l; y <= r; y++) {
        int day=0;
        for(int m=0;m<12;m++){
            for(int d=0;d<month[m];d++){
                if(m<=1){
                    if(m==1&&d==28){
                        if(isrun(y)==false)continue;
                        if((day+y11[y])%7<=5&&(day+y11[y])%7>=1)add[365]++;
                        day++;
                        continue;
                    }
                    if((day+y11[y])%7<=5&&(day+y11[y])%7>=1)add[day]++;
                    day++;
                }
                else{
                    if((day+y11[y])%7<=5&&(day+y11[y])%7>=1){
                        if(isrun(y)==false)add[day]++;
                        else add[day-1]++;
                    }
                    day++;
                }
            }
        }
    }
    

    sort(add.begin(),add.end());
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=add[i];
    }
    cout<<sum<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    y11[2025] = 3;
    for (int y = 2026; y <= 2075; ++y) {
        int p = y - 1;
        int days = isrun(p) ? 366 : 365;
        y11[y] = (y11[p] + days) % 7;
    }

    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}